static mut KEYWORDS: [(&str, TokenType); 2] =
    [("fn", TokenType::FUNCTION), ("let", TokenType::LET)];

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum TokenType {
    ILLEGAL,
    EOF, // 文件结尾

    // 标识符+字面量
    IDENT,
    // add, foobar, x, y
    INT, // 1343456

    // 运算符
    ASSIGN,
    PLUS,

    // 分隔符
    COMMA,
    SEMICOLON,

    LPAREN,
    RPAREN,
    LBRACE,
    RBRACE,

    // 关键字
    FUNCTION,
    LET,
}

#[derive(Debug, PartialEq)]
pub struct Token {
    pub Literal: String,
    pub Type: TokenType,
}

impl Token {
    pub fn new(literal: String, Type: TokenType) -> Token {
        Token {
            Literal: literal,
            Type,
        }
    }
}

// 判断是不是标识符
pub fn LookupIdent(ident: &String) -> TokenType {
    for (k, v) in unsafe { KEYWORDS.iter() } {
        if *k == ident {
            return *v;
        }
    }
    TokenType::IDENT
}
